package com.alibaba.cirtus.ots.application.app.ability.facade.v2serviceimpl;

import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.crunifiedinventory.service.CrUnifiedInventoryService;
import com.epoch.app.otsapplicationappsdk.transferorderdetail.dto.InitRequest;
import com.epoch.app.otsapplicationappsdk.transferorderdetail.service.TransferOrderDetailService;
import com.epoch.app.crunifiedinventory.dto.request.AllocateOrderDetailSearchRequest;
import com.epoch.app.crunifiedinventory.dto.response.AllocateOrderDetailVO;
import com.epoch.app.crunifiedinventory.dto.response.AllocateOrderDetailsQueryResponse;
import com.epoch.app.crunifiedinventory.model.dto.AllocateOrderQueryRequest;
import lombok.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TransferOrderDetailV2ServiceImpl implements TransferOrderDetailService {

    private static Log log = Log.getLogger(TransferOrderDetailV2ServiceImpl.class);

//    @Resource
//    OtsUnifiedInventoryService otsUnifiedInventoryService;
    @Resource
    CrUnifiedInventoryService otsUnifiedInventoryService;
    @Override
    public Object init(InitRequest initRequest) {
        log.info("调拨单详情渲染 请求参数 {} " , JSON.toJSONString(initRequest));
        JSONObject result = new JSONObject();
        try {
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(initRequest.getRequestBody()));
            String code =jsonObject.getString("code");

            //头部标题
            AllocateOrderQueryRequest allocateOrderQueryRequest = new AllocateOrderQueryRequest();
            allocateOrderQueryRequest.setCode(code);
            Result<AllocateOrderDetailsQueryResponse> itemResult= otsUnifiedInventoryService.allocateOrderQuery(allocateOrderQueryRequest);
            result.put("item",itemResult.getResult());

       /* //详情展示模块
        List<InfoList> infoList = new ArrayList<>();

        InfoList infoList1 = new InfoList();
        infoList1.setLabel("类型");
        infoList1.setValue(itemInfo.getString("typeDesc"));

        InfoList infoList2 = new InfoList();
        infoList2.setLabel("收货仓");
        infoList2.setValue(itemInfo.getString("receiveAreaName"));

        InfoList infoList3 = new InfoList();
        infoList3.setLabel("单据类型");
        infoList3.setValue("");

        InfoList infoList4 = new InfoList();
        infoList4.setLabel("提报人");
        infoList4.setValue("丽萍");*/


        /*//添加明细
        infoList.add(infoList1);
        infoList.add(infoList2);
        infoList.add(infoList2);
        infoList.add(infoList2);
        result.put("infoList",infoList);*/

            AllocateOrderDetailSearchRequest allocateOrderDetailSearchRequest = new AllocateOrderDetailSearchRequest();
            allocateOrderDetailSearchRequest.setCode(allocateOrderQueryRequest.getCode());
            Result<List<AllocateOrderDetailVO>> allocateOrderDetailVO = otsUnifiedInventoryService.allocateOrderSearch(allocateOrderDetailSearchRequest);
            result.put("info",allocateOrderDetailVO.getResult());
            result.put("success",true);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("调拨单详情渲染 异常 {} " , e.getMessage());
            result.put("success",false);
            result.put("message","调拨单详情渲染异常");
        }
        return result;



    }

    @Data
    public class  InfoList{
        //标题
        private String label;

        //内容
        private  String  value;
    }

    @Data
    public class Good{
        //货品名称
        private String goodsName;

        //预报数量/货品数量/计划量
        private String goodsNum;

        //生产日期
        private String produceDate;

        //预分配量
        private String preGiv;

        //可用库存
        private String store;

        //单号
        private String order;

        //单位
        private String unit;

        //数量
        private String goodNUmber;

    }

}
